-- An example involving defining types and some algorithmic computation

sorting is package{
  
  msort has type (list of %t) => list of %t where comparable over %t;
  msort(list{X}) is list{X};
  msort(list{}) is list{};
  msort(list{pivot;..L})  is let{
    split(list{},Lf,R) is (Lf,R);
    split(list{E;..more},Lf,R) where E<pivot is split(more,list{E;..Lf},R);
    split(list{E;..more},Lf,R) default is split(more,Lf,list{E;..R});
    
    (LL,RR) is split(L,list{},list{});
   } in msort(LL)<>list{pivot;..msort(RR)};
   
  ordered has type (list of %t) => boolean where comparable over %t;
  ordered(list{}) is true;
  ordered(list{H;..T}) is let{
    ordList(list{},_) is true;
    ordList(list{E;..R},C) where C<=E is ordList(R,E);
    ordList(_,_) default is false;
  } in ordList(T,H);   
}
